package com.yenlien.traceyun.business.config;

import com.qiniu.common.Zone;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.security.PublicKey;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-12
 * @description:七牛配置
 */
@Configuration
public class QiniuConfig {

    @Value("${qiniu.accessKey}")
    private String accessKey;

    @Value("${qiniu.secret}")
    private String secret;

    @Value("${qiniu.bucket}")
    private String bucket;

    @Value("${qiniu.path}")
    private String path;

    @Bean
    public com.qiniu.storage.Configuration configuration() {
        return new com.qiniu.storage.Configuration(Zone.zone2());
    }

    @Bean
    public UploadManager uploadManager() {
        return new UploadManager(configuration());
    }

    @Bean
    public Auth auth() {
        return Auth.create(accessKey, secret);
    }

    @Bean
    public BucketManager bucketManager() {
        return new BucketManager(auth(), configuration());
    }
}
